package examples.mail;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.io.Util;
import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPReply;
import org.apache.commons.net.smtp.SimpleSMTPHeader;

public class SMTPMail {

	public static void main(String[] args) throws Exception {

		
		String toserver = "183.62.125.223";
		
		String mailserver = "mail.easou.cn";
		
		String from = "milo_li@staff.easou.com";
		
		String to = "o21x@qq.com";
		
		String subject = "sadfasdffhdfgf";
		String htmlcontent =  "sdfsdfadfgbfdjhfhjgfdsgsdfgsdfg";
	 
		
		
		 String mail = MailBuild.build(mailserver, from, to, subject,htmlcontent, htmlcontent);
		
		 System.out.println(mail);

		 SMTPMail.send(from, to, toserver, mailserver, mail);
	}

	public static void send(String from, String to, String toserver, String mailserver, String mail) throws Exception {
		Writer writer;
		SMTPClient client;
		client = new SMTPClient();
		client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
		client.connect(toserver);
		client.login(mailserver);
		client.setSender(from);
		client.addRecipient(to);
		writer = client.sendMessageData();
		writer.write(mail);
		writer.close();
		client.completePendingCommand();
		client.logout();  
		client.disconnect();
	}

	private void error(String to, String msg) {
	}

	private void ok(String to) {
	}

}
